
<!-- 废物循环减碳编辑业务实现-->
<template>
  <!-- 新增&修改 start-->
  <vxe-modal :modelValue="isEditFormVisible" :show-footer="true" :position="dialogPosition" :title="title" :width="dialogWidth" :height="dilogHeight" resize="" :before-hide-method="beforeCloseDialog">
    <el-form inline-message status-icon ref="dataFormRef" :rules="verify" :model="formData" label-position="right" label-width="120px" require-asterisk-position="right">
      <el-form-item label="主键" prop="id" v-show="false">
        <el-input v-model="formData.id" :readonly="isReadOnly"/>
      </el-form-item>
      <el-form-item label="废物名称" prop="wasteNeme">
        <el-input v-model="formData.wasteNeme" :columnInfo="{columnName:'废物名称',readonly:isReadOnly}" />
      </el-form-item>
      <el-form-item label="规格/容量" prop="capacity">
        <el-input v-model="formData.capacity" :columnInfo="{columnName:'规格/容量',readonly:isReadOnly}" />
      </el-form-item>
        <el-form-item label="周次" prop="week">
        今年的第
        <el-input-number v-model="formData.week" :min="1" :max="52" @change="handleWeekChange" :columnInfo="{columnName:'周次',readonly:isReadOnly}" />
        周
      </el-form-item>
      <!-- <el-form-item label="周次">
        <lxsh-common-dictionary-comb v-model="formData.week" :dictionaryCode="'YEAR_WEEK'" :columnInfo="{columnName:'周次',readonly:isReadOnly}" />
      </el-form-item> -->
      <el-form-item label="开始时间" prop="stratTime">
        <el-date-picker v-model="formData.stratTime" value-format="YYYY-MM-DD 00:00:00" type="date" :columnInfo="{columnName:'开始时间',readonly:isReadOnly}"/>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker v-model="formData.endTime" value-format="YYYY-MM-DD 00:00:00" type="date" :columnInfo="{columnName:'结束时间',readonly:isReadOnly}"/>
      </el-form-item>
      <el-form-item label="数量" prop="count">
        <el-input type="number" :controls="false" v-model.number="formData.count" :columnInfo="{columnName:'数量',readonly:isReadOnly}"  @change="changeCount"/>
      </el-form-item>
      <el-form-item label="减碳量" prop="reduceCount">
        <el-input type="number" :controls="false" v-model.number="formData.reduceCount" :columnInfo="{columnName:'减碳量',readonly:isReadOnly}" />
      </el-form-item>
    </el-form>
	<template #footer>
		<el-button @click="beforeCloseDialog()">取消</el-button>
		<el-button type="primary" @click="onSubmit(dataFormRef)">确定</el-button>
	</template>
  </vxe-modal>
  <!-- 新增&修改 end-->
</template>
<script lang="ts" setup>
  import { hooksForCommonForm } from 'hhlt-vue/src/components/Lxsh/Common/hooksForCommonForm'
  import { Ref, ref, toRefs,onBeforeMount } from "vue"
  import { FormInstance } from 'element-plus';
  import { ICerWasteImpro, CerWasteImpro } from 'lxsh-cer-web-pc/src/model/cer/cer/waste-impro/cer-waste-impro'
  import { IPageInfo } from 'hhlt-core/src/model/page/pageInfo';
import dateUtils from "lxsh-cer-web-pc/src/utils/common/dateUtlis";
import cerWasteImproApi from 'lxsh-cer-web-pc/src/api/cer/cer/cerWasteImproApi';


  interface ICommonFormProps {
    //官方暂不支持import props暂定解决方案，等后期支持后删除，issue #4294
    pageInfo:IPageInfo<ICerWasteImpro>;
	  functionDistinguish:string;
      isEditFormVisible:Boolean;
  }
  //获取props参数
  const props = defineProps<ICommonFormProps>()
  //获取form实例
  const dataFormRef:Ref<FormInstance | undefined> = ref<FormInstance>();
  //自定义事件[本编辑界面处理完成]
  const emits = defineEmits(['editProcessSuccess'])
  //hooks初始化
  const {commonData,title,dialogPosition,dilogHeight,isReadOnly,beforeCloseDialog,onSubmit} = hooksForCommonForm<CerWasteImpro>(new CerWasteImpro(),dataFormRef,props,emits)
  //返回vue界面需要使用到的data
  const { dialogWidth,formData,verify} = toRefs(commonData)



onBeforeMount(() => {
  formData.value.week = dateUtils.getCurrentWeek().weekNum;
  formData.value.stratTime = dateUtils.getCurrentWeek().startDate;
  formData.value.endTime = dateUtils.getCurrentWeek().endDate;
});
let handleWeekChange = (e: any) => {
  console.log(e, "=====");
  let rand = dateUtils.getDateForCurrentWeek(e);
  formData.value.stratTime = rand[0];
  formData.value.endTime = rand[1];
};


let boxCoef = 0; //灯的系数
cerWasteImproApi.getTypeGroupComboByGroup((res) => {
  if (res.success && res.hasData) {
    res.list.forEach((i) => {
      let text = new String(i.text);
      if (text.indexOf("桶") != -1) {
        if (i.otherInfo) {
          boxCoef = JSON.parse(i.otherInfo).coefficient;
        }
      }
     
    });
  }
});

const changeCount = ()=>{
  formData.value.reduceCount  = formData.value.count * boxCoef
}


</script>
